﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using Shop_Phone.Entities;

namespace Shop_Phone.COMM
{
    public class Admins
    {
        public Entities.khuyenmai getby_khuyenmai(string _masanpham, string _ngaybatdau, string _ngayketthuc, ref string errMsg)
        {
            try
            {
                string sqlstr = "select * from khuyenmai where  masanpham like  N'" + _masanpham + "' and CONVERT(nvarchar(20),ngaybatdau,105)  = '" + _ngaybatdau + "' and CONVERT(nvarchar(20),ngayketthuc,105)  = '" + _ngayketthuc + "'";
                IDataReader dr = SQLExecute.getIDataReader(sqlstr, ref errMsg);
                Entities.khuyenmai obj = new Entities.khuyenmai();
                obj = (Entities.khuyenmai)CBO.FillObject(dr, typeof(Entities.khuyenmai));
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public Entities.giamgia getby_giamgia(string _masanpham, string _ngaybatdau, string _ngayketthuc, ref string errMsg)
        {
            try
            {
                string sqlstr = "select * from giamgia where  masanpham like  N'" + _masanpham + "' and CONVERT(nvarchar(20),ngaybatdau,105)  = '" + _ngaybatdau + "' and CONVERT(nvarchar(20),ngayketthuc,105)  = '" + _ngayketthuc + "'";
                IDataReader dr = SQLExecute.getIDataReader(sqlstr, ref errMsg);
                Entities.giamgia obj = new Entities.giamgia();
                obj = (Entities.giamgia)CBO.FillObject(dr, typeof(Entities.giamgia));
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public khachhang getby_tk_khachhang(string _tentaikhoan, ref string errMsg)
        {
            try
            {
                string sqlstr = "select * from khachhang where  tendangnhap like  N'" + _tentaikhoan + "'";
                IDataReader dr = SQLExecute.getIDataReader(sqlstr, ref errMsg);
                khachhang obj = new khachhang();
                obj = (khachhang)CBO.FillObject(dr, typeof(khachhang));
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public users getby_tk_users_ten(string _tentaikhoan, ref string errMsg)
        {
            try
            {
                string sqlstr = "select * from users where  username like  N'" + _tentaikhoan + "'";
                IDataReader dr = SQLExecute.getIDataReader(sqlstr, ref errMsg);
                users obj = new users();
                obj = (users)CBO.FillObject(dr, typeof(users));
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public hoadon getby_hoadon(string _mahodon, ref string errMsg)
        {
            try
            {
                string sqlstr = "select * from hoadon where  mahoadon like  N'" + _mahodon + "'";
                IDataReader dr = SQLExecute.getIDataReader(sqlstr, ref errMsg);
                hoadon obj = new hoadon();
                obj = (hoadon)CBO.FillObject(dr, typeof(hoadon));
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public danhmucsanpham getby_dmsanpham(string _madanhmuc, ref string errMsg)
        {
            try
            {
                string sqlstr = "select * from danhmucsanpham where  madanhmuc like  N'" + _madanhmuc + "'";
                IDataReader dr = SQLExecute.getIDataReader(sqlstr, ref errMsg);
                danhmucsanpham obj = new danhmucsanpham();
                obj = (danhmucsanpham)CBO.FillObject(dr, typeof(danhmucsanpham));
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public users getby_tk_users_id(string _userid, ref string errMsg)
        {
            try
            {
                string sqlstr = "select * from users where  userid like  N'" + _userid + "'";
                IDataReader dr = SQLExecute.getIDataReader(sqlstr, ref errMsg);
                users obj = new users();
                obj = (users)CBO.FillObject(dr, typeof(users));
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public Entities.sanpham getby_sanpham(string _masanpham, ref string errMsg)
        {
            try
            {
                string sqlstr = "select * from sanpham where  masanpham like  N'" + _masanpham + "'";
                IDataReader dr = SQLExecute.getIDataReader(sqlstr, ref errMsg);
                Entities.sanpham obj = new Entities.sanpham();
                obj = (Entities.sanpham)CBO.FillObject(dr, typeof(Entities.sanpham));
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public int save_danhmucsanpham(danhmucsanpham vdanhmucsanpham, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@madanhmuc", vdanhmucsanpham.Madanhmuc);
                i = i + 1;
                prms[i] = new SqlParameter("@tendanhmuc", vdanhmucsanpham.Tendanhmuc);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("dbo.sp_save_danhmucsanpham", ref prms, 3, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public int save_giamgia(giamgia vgiamgia, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[7];
                prms[i] = new SqlParameter("@masanpham", vgiamgia.Masanpham);
                i = i + 1;
                prms[i] = new SqlParameter("@giamoi", vgiamgia.Giamoi);
                i = i + 1;
                prms[i] = new SqlParameter("@trangthai", vgiamgia.Trangthai);
                i = i + 1;
                prms[i] = new SqlParameter("@ngaybatdau", vgiamgia.Ngaybatdau);
                i = i + 1;
                prms[i] = new SqlParameter("@ngayketthuc", vgiamgia.Ngayketthuc);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("dbo.sp_save_giamgia", ref prms, 6, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public int capnhap_tt_giamgia(giamgia vgiamgia, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[6];
                prms[i] = new SqlParameter("@masanpham", vgiamgia.Masanpham);
                i = i + 1;
                prms[i] = new SqlParameter("@trangthai", vgiamgia.Trangthai);
                i = i + 1;
                prms[i] = new SqlParameter("@ngaybatdau", vgiamgia.Ngaybatdau);
                i = i + 1;
                prms[i] = new SqlParameter("@ngayketthuc", vgiamgia.Ngayketthuc);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("dbo.sp_capnhap_tt_giamgia", ref prms, 5, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public int duyet_hoadon(string _mahoadon, bool _trangthai, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@mahoadon", _mahoadon);
                i = i + 1;
                prms[i] = new SqlParameter("@trangthai", _trangthai);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("dbo.sp_duyet_hoadon", ref prms, 3, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public int capnhap_soluong(string _masanpham, int _soluong, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@masanpham", _masanpham);
                i = i + 1;
                prms[i] = new SqlParameter("@soluong", _soluong);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("dbo.sp_capnhap_sl_sanpham", ref prms, 3, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public int capnhap_tt_khachhang(string _tendangnhap, bool _trangthai, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@tendangnhap", _tendangnhap);
                i = i + 1;
                prms[i] = new SqlParameter("@trangthai", _trangthai);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("dbo.sp_trangthai_khachhang", ref prms, 3, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public int capnhap_tt_Users(string _tendangnhap, bool _trangthai, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@username", _tendangnhap);
                i = i + 1;
                prms[i] = new SqlParameter("@trangthai", _trangthai);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("dbo.sp_trangthai_users", ref prms, 3, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public int Login_users(string _username, string _password, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@username", _username);
                i = i + 1;
                prms[i] = new SqlParameter("@password", _password);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("dbo.sp_login", ref prms, 3, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public int save_khuyenmai(khuyenmai vkhuyenmai, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[7];
                prms[i] = new SqlParameter("@masanpham", vkhuyenmai.Masanpham);
                i = i + 1;
                prms[i] = new SqlParameter("@khuyenmai", vkhuyenmai.NDKhuyenmai);
                i = i + 1;
                prms[i] = new SqlParameter("@trangthai", vkhuyenmai.Trangthai);
                i = i + 1;
                prms[i] = new SqlParameter("@ngaybatdau", vkhuyenmai.Ngaybatdau);
                i = i + 1;
                prms[i] = new SqlParameter("@ngayketthuc", vkhuyenmai.Ngayketthuc);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("dbo.sp_save_khuyenmai", ref prms, 6, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public int capnhap_tt_khuyenmai(khuyenmai vkhuyenmai, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[6];
                prms[i] = new SqlParameter("@masanpham", vkhuyenmai.Masanpham);
                i = i + 1;
                prms[i] = new SqlParameter("@trangthai", vkhuyenmai.Trangthai);
                i = i + 1;
                prms[i] = new SqlParameter("@ngaybatdau", vkhuyenmai.Ngaybatdau);
                i = i + 1;
                prms[i] = new SqlParameter("@ngayketthuc", vkhuyenmai.Ngayketthuc);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("dbo.sp_capnhap_tt_khuyenmai", ref prms, 5, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        

        public int save_users(users vusers, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[10];
                prms[i] = new SqlParameter("@userid", vusers.Userid);
                i = i + 1;
                prms[i] = new SqlParameter("@username", vusers.Username);
                i = i + 1;
                prms[i] = new SqlParameter("@password", vusers.Password);
                i = i + 1;
                prms[i] = new SqlParameter("@usertype", vusers.Usertype);
                i = i + 1;
                prms[i] = new SqlParameter("@hoten", vusers.Hoten);
                i = i + 1;
                prms[i] = new SqlParameter("@diachi", vusers.Diachi);
                i = i + 1;
                prms[i] = new SqlParameter("@sodienthoai", vusers.Sodienthoai);
                i = i + 1;
                prms[i] = new SqlParameter("@trangthai", vusers.Trangthai);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("dbo.sp_save_users", ref prms, 9, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public int save_sanpham(Entities.sanpham vsanpham, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[16];
                prms[i] = new SqlParameter("@masanpham", vsanpham.Masanpham);
                i = i + 1;
                prms[i] = new SqlParameter("@madanhmuc", vsanpham.Madanhmuc);
                i = i + 1;
                prms[i] = new SqlParameter("@tensanpham", vsanpham.Tensanpham);
                i = i + 1;
                prms[i] = new SqlParameter("@giasanpham", vsanpham.Giasanpham);
                i = i + 1;
                prms[i] = new SqlParameter("@phukiendikem", vsanpham.Phukiendikem);
                i = i + 1;
                prms[i] = new SqlParameter("@baohanh", vsanpham.Baohanh);
                i = i + 1;
                prms[i] = new SqlParameter("@tinhnang", vsanpham.Tinhnang);
                i = i + 1;
                prms[i] = new SqlParameter("@thongso", vsanpham.Thongso);
                i = i + 1;
                prms[i] = new SqlParameter("@hinhanh", vsanpham.Hinhanh);
                i = i + 1;
                prms[i] = new SqlParameter("@luotxem", vsanpham.Luotxem);
                i = i + 1;
                prms[i] = new SqlParameter("@ngaydang", vsanpham.Ngaydang);
                i = i + 1;
                prms[i] = new SqlParameter("@trangthai", vsanpham.Trangthai);
                i = i + 1;
                prms[i] = new SqlParameter("@soluong", vsanpham.Soluong);
                i = i + 1;
                prms[i] = new SqlParameter("@spnoibat", vsanpham.Spnoibat);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("dbo.sp_save_sanpham", ref prms, 15, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public DataTable getall_sanpham_page(int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_sanpham_page]", ref prms, 3, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public DataTable getall_hoadon_page(int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_hoadon_page]", ref prms, 3, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public DataTable getall_dmsanpham_page(int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_danhmucsanpham_page]", ref prms, 3, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public DataTable getall_giamgia_page(int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_giamgia_page]", ref prms, 3, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public DataTable getall_khuyenmai_page(int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_khuyenmai_page]", ref prms, 3, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public DataTable getall_khachhang_page(int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_khachhang_page]", ref prms, 3, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public DataTable getall_users_page(int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_users_page]", ref prms, 3, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public DataTable getall_danhthu(int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_danhthu]", ref prms, 3, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public DataTable getall_danhthu_para(DateTime _ngaydat, int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                SqlParameter[] prms = new SqlParameter[5];
                prms[i] = new SqlParameter("@ngaydat", _ngaydat);
                i = i + 1;
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_danhthu_para]", ref prms, 4, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public DataTable getall_sanpham_dm(string _madanhmuc, ref string errMsg)
        {
            try
            {
                SqlParameter[] prms = new SqlParameter[1];
                prms[0] = new System.Data.SqlClient.SqlParameter("@madanhmuc", _madanhmuc);
                DataTable dtTon_VatTu = null;
                dtTon_VatTu = SQLExecute.LoadDataFromDB("[dbo].[sp_getall_sanpham_dm]", "tmpData", ref errMsg, CommandType.StoredProcedure, prms, 1);
                return dtTon_VatTu;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                throw ex;
            }
        }

        public DataTable getall_chitiet_hd(string _mahoadon, ref string errMsg)
        {
            try
            {
                SqlParameter[] prms = new SqlParameter[1];
                prms[0] = new System.Data.SqlClient.SqlParameter("@mahoadon", _mahoadon);
                DataTable dtTon_VatTu = null;
                dtTon_VatTu = SQLExecute.LoadDataFromDB("[dbo].[sp_getall_chitiet_hd]", "tmpData", ref errMsg, CommandType.StoredProcedure, prms, 1);
                return dtTon_VatTu;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                throw ex;
            }
        }

        public DataTable getall_danhmucsanpham(ref string errMsg)
        {
            try
            {
                errMsg = "";
                DataTable tbl = SQLExecute.LoadDataFromDB2("[dbo].[sp_getall_danhmucsanpham]", "tmpData", ref errMsg);
                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }
    }
}